package Math;

import java.util.Scanner;

public class APIMathdemo03 {
    //153=1^3+5^3+3^3
    //一个n位数等于
    public static void main(String[] args) {
        System.out.println("请输入一个数");
        Scanner sc = new Scanner(System.in);
        int num = sc.nextInt();
        boolean result = fun(num);
        if (result) {
            System.out.println(num + "是一个水仙花数");
        } else {
            System.out.println(num + "不是一个水仙花数");
        }

    }

    private static boolean fun(int num) {
        int count = 0;
        int ret = num;
        //计算num有几位数
        while (ret != 0) {
            count++;
            ret /= 10;
        }
        ret = num;
        int sum = 0;
        while (ret != 0) {
            sum += Math.pow(ret % 10, count);
            ret /= 10;
        }
        if (sum == num) {
            return true;
        } else {
            return false;
        }

    }
}
